﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TalentRecruitmentSystem.Service;
using TalentRecruitmentSystem.Manage;
using System.Data;

namespace TalentRecruitmentSystem.Pages
{
    public partial class PositionSearch : System.Web.UI.Page
    {
        CompanyInfoManage cm = new CompanyInfoManage();
        UserInfo userInfo = new UserInfo();
        string Name = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            //string str = Session["stringInSession"].ToString();
            string str2 = Session["perInSession"].ToString();
            if (str2 != null)
            {
                Name = Session["perInSession"].ToString(); 
            }
            //if (str != "")
            //{
            //    Name = Session["stringInSession"].ToString();
            //}
            //else if (str2 != null)
            //{
            //    Name = Session["perInSession"].ToString();
            //}
            Label1.Text = Name;
        }
        private void DataBind2()
        {
            string compaynname = TextBox1.Text;
            CompanyInfo companyInfo = cm.GetCompanyInfoByName(compaynname);
            if (companyInfo != null)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("CompanyName");
                dt.Columns.Add("WorkPlace");
                dt.Columns.Add("Companywebsite");
                dt.Columns.Add("Publishposition");
                dt.Columns.Add("LinkPhone");
                dt.Columns.Add("LinkPerson");
                dt.Columns.Add("ConcourNumber");
                dt.Rows.Add(companyInfo.CompanyName, companyInfo.WorkPlace, companyInfo.Companywebsite, companyInfo.Publishposition, companyInfo.LinkPhone, companyInfo.LinkPerson, companyInfo.ConcourNumber);
                GridView1.DataSource = dt;
            }
            else
            {
                Response.Write("<script>window.alert('你搜索的结果不存在！');</script>");
            }
        }
        private void DataBind1()
        {
            string trad = DropDownList1.Text;
            string protation = DropDownList2.Text;
            string palce = DropDownList3.Text;
            List<CompanyInfo> cmopanyInfos = cm.GetCompanyInfosByParameter(trad, protation, palce);
            DataTable dt = new DataTable();
            dt.Columns.Add("CompanyName");
            dt.Columns.Add("WorkPlace");
            dt.Columns.Add("Companywebsite");
            dt.Columns.Add("Publishposition");
            dt.Columns.Add("LinkPhone");
            dt.Columns.Add("LinkPerson");
            dt.Columns.Add("ConcourNumber");
            foreach (CompanyInfo c in cmopanyInfos)
            {
                dt.Rows.Add(c.CompanyName, c.WorkPlace, c.Companywebsite, c.Publishposition, c.LinkPhone, c.LinkPerson, c.ConcourNumber);
            }
            GridView1.DataSource = dt;
        }
        protected void GridView1_DataBinding(object sender, EventArgs e)
        {
            if (RadioButton1.Checked)
            {
                DataBind2();
            }
            else
            {
                TextBox1.Text = "";
                DataBind1();
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            GridView1.DataBind();
            Button1.Text = "投递简历";
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in GridView1.Rows)
            {

                CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
                if (cb.Checked)
                {
                    string str = row.Cells[1].Text;
                    CompanyInfo companyInfo = cm.GetCompanyInfoByName(str);
                    if (companyInfo.Jobhunter != null)
                    {
                        companyInfo.Jobhunter = companyInfo.Jobhunter + "," + Name;
                    }
                    else
                    {
                        companyInfo.Jobhunter = Name;
                    }
                    cm.Update(companyInfo);
                }
            }
            Response.Write("<script>window.alert('投递成功！');</script>");
        }
    }
}